// 引入接口地址
import { menuList } from '../../../request/api'
// 定义接口
interface menuState {
  menuList: Array<Object>
}
// 菜单仓库模块
const state = {
  menuList: []
}

const mutations = {
  REQ_MENULIST (state: menuState, payload: any) {
    return (state.menuList = payload)
  }
}

const actions = {
  menuList_Action ({ commit }: any) {
    // 调用菜单列表接口
    menuList({ istree: true }).then((res: any) => {
      console.log(res)
      if (res.data.code == 200) {
        commit('REQ_MENULIST', res.data.list)
      }
    })
  }
}

const getters = {
  // 获取菜单列表
  getMenuList (state: menuState) {
    return state.menuList
  }
}

// 导出菜单仓库
export default {
  state,
  mutations,
  actions,
  getters,
  namespaced: true
}
